home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet internetowy / Przegladarki internetowe / Mozilla Seamonkey 1.0.5 pl / seamonkey-1.0.5.pl-PL.win32.installer.exe / BROWSER.XPI / bin / chrome / toolkit.jar / content / global / finddialog.js < prev    next >
Encoding:
JavaScript  |  2004-11-27  |  6.0 KB  |  168 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is Mozilla Communicator client code, released
  17.  * March 31, 1998.
  18.  *
  19.  * The Initial Developer of the Original Code is
  20.  * Netscape Communications Corporation.
  21.  * Portions created by the Initial Developer are Copyright (C) 1998
  22.  * the Initial Developer. All Rights Reserved.
  23.  *
  24.  * Contributor(s):
  25.  *   Alec Flett       <alecf@netscape.com>
  26.  *   Bill Law         <law@netscape.com>
  27.  *   Blake Ross       <blakeross@telocity.com>
  28.  *   Dean Tessman     <dean_tessman@hotmail.com>
  29.  *   Matt Fisher      <matt@netscape.com>
  30.  *   Simon Fraser     <sfraser@netscape.com>
  31.  *   Stuart Parmenter <pavlov@netscape.com>
  32.  *
  33.  * Alternatively, the contents of this file may be used under the terms of
  34.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  35.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  36.  * in which case the provisions of the GPL or the LGPL are applicable instead
  37.  * of those above. If you wish to allow use of your version of this file only
  38.  * under the terms of either the GPL or the LGPL, and not to allow others to
  39.  * use your version of this file under the terms of the MPL, indicate your
  40.  * decision by deleting the provisions above and replace them with the notice
  41.  * and other provisions required by the GPL or the LGPL. If you do not delete
  42.  * the provisions above, a recipient may use your version of this file under
  43.  * the terms of any one of the MPL, the GPL or the LGPL.
  44.  *
  45.  * ***** END LICENSE BLOCK ***** */
  46.  
  47. var dialog;     // Quick access to document/form elements.
  48. var gFindInst;   // nsIWebBrowserFind that we're going to use
  49. var gFindInstData; // use this to update the find inst data
  50.  
  51. function initDialogObject()
  52. {
  53.   // Create dialog object and initialize.
  54.   dialog = new Object;
  55.   dialog.findKey         = document.getElementById("dialog.findKey");
  56.   dialog.caseSensitive   = document.getElementById("dialog.caseSensitive");
  57.   dialog.wrap            = document.getElementById("dialog.wrap");
  58.   dialog.searchBackwards = document.getElementById("dialog.searchBackwards");
  59.   dialog.find            = document.getElementById("findDialog").getButton("accept");
  60.   dialog.bundle          = null;
  61.  
  62.   // Move dialog to center, if it not been shown before
  63.   var windowElement = document.getElementById("findDialog");
  64.   if (!windowElement.hasAttribute("screenX") || !windowElement.hasAttribute("screenY"))
  65.   {
  66.     sizeToContent();
  67.     moveToAlertPosition();
  68.   }
  69. }
  70.  
  71. function fillDialog()
  72. {
  73.   // get the find service, which stores global find state
  74.   var findService = Components.classes["@mozilla.org/find/find_service;1"]
  75.                          .getService(Components.interfaces.nsIFindService);
  76.   
  77.   // Set initial dialog field contents. Use the gFindInst attributes first,
  78.   // this is necessary for window.find()
  79.   dialog.findKey.value           = gFindInst.searchString ? gFindInst.searchString : findService.searchString;
  80.   dialog.caseSensitive.checked   = gFindInst.matchCase ? gFindInst.matchCase : findService.matchCase;
  81.   dialog.wrap.checked            = gFindInst.wrapFind ? gFindInst.wrapFind : findService.wrapFind;
  82.   dialog.searchBackwards.checked = gFindInst.findBackwards ? gFindInst.findBackwards : findService.findBackwards;
  83. }
  84.  
  85. function saveFindData()
  86. {
  87.   // get the find service, which stores global find state
  88.   var findService = Components.classes["@mozilla.org/find/find_service;1"]
  89.                          .getService(Components.interfaces.nsIFindService);
  90.  
  91.   // Set data attributes per user input.
  92.   findService.searchString  = dialog.findKey.value;
  93.   findService.matchCase     = dialog.caseSensitive.checked;
  94.   findService.wrapFind      = dialog.wrap.checked;
  95.   findService.findBackwards = dialog.searchBackwards.checked;
  96. }
  97.  
  98. function onLoad()
  99. {
  100.   initDialogObject();
  101.  
  102.   // get the find instance
  103.   var arg0 = window.arguments[0];
  104.   // If the dialog was opened from window.find(),
  105.   // arg0 will be an instance of nsIWebBrowserFind
  106.   if (arg0 instanceof Components.interfaces.nsIWebBrowserFind) {
  107.     gFindInst = arg0;
  108.   } else {
  109.     gFindInstData = arg0;
  110.     gFindInst = gFindInstData.webBrowserFind;
  111.   }
  112.  
  113.   fillDialog();
  114.   doEnabling();
  115.  
  116.   if (dialog.findKey.value)
  117.     dialog.findKey.select();
  118.   dialog.findKey.focus();
  119. }
  120.  
  121. function onUnload()
  122. {
  123.     window.opener.findDialog = 0;
  124. }
  125.  
  126. function onAccept()
  127. {
  128.   if (gFindInstData && gFindInst != gFindInstData.webBrowserFind) {
  129.     gFindInstData.init();
  130.     gFindInst = gFindInstData.webBrowserFind;
  131.   }
  132.  
  133.   // Transfer dialog contents to the find service.
  134.   saveFindData();
  135.  
  136.   // set up the find instance
  137.   gFindInst.searchString  = dialog.findKey.value;
  138.   gFindInst.matchCase     = dialog.caseSensitive.checked;
  139.   gFindInst.wrapFind      = dialog.wrap.checked;
  140.   gFindInst.findBackwards = dialog.searchBackwards.checked;
  141.   
  142.   // Search.
  143.   var result = gFindInst.findNext();
  144.  
  145.   if (!result)
  146.   {
  147.     if (!dialog.bundle)
  148.       dialog.bundle = document.getElementById("findBundle");
  149.  
  150.     try {
  151.       var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
  152.       promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
  153.       promptService.alert(window, null,
  154.                           dialog.bundle.getString("notFoundWarning"));
  155.     }
  156.     catch (e) { dump("The text you entered was not found."); }
  157.  
  158.     dialog.findKey.select();
  159.     dialog.findKey.focus();
  160.   } 
  161.   return false;
  162. }
  163.  
  164. function doEnabling()
  165. {
  166.   dialog.find.disabled = !dialog.findKey.value;
  167. }
  168.